<script setup lang="ts">
import { ref } from "vue"
interface Props {
  ifm: any
}
const props = withDefaults(defineProps<Props>(), {
  ifm: null
})
const { ipcRenderer } = require('electron')
const isDown = ref(false)
const baseX = ref(0)
const baseY = ref(0)

// 移动窗口----start
function winDown(e: any) {
  isDown.value = true 
  baseX.value = e.x
  baseY.value = e.y
}
function winMove(e: any) {
  if(isDown.value){
    const x = e.screenX - baseX.value
    const y = e.screenY - baseY.value
    ipcRenderer.send('move',{
      posX: x,
      posY: y
    })
  }
}
function winUp() {
  isDown.value = false;
}
</script>

<template>
<div
  class="top-column"
  @dblclick="ipcRenderer.send('max')"
  @mousedown="winDown"
  @mousemove="winMove"
  @mouseup="winUp"
>
  <div class="top-left">
    <div class="logo">
      <img src="@/icons/appIcon.png" />
      Bytoken
    </div>
    <div class="hostiry">
      <el-icon @click="ifm.contentWindow.history.back()"><Back /></el-icon>
      <el-icon @click="ifm.contentWindow.history.forward();"><Right /></el-icon>
    </div>
  </div>
  <div class="seach">
    <el-input placeholder="搜索币种/资讯" size="small">
      <template #prefix>
        <el-icon class="el-input__icon"><search /></el-icon>
      </template>
    </el-input>
  </div>
  <div class="top-right">
    <div class="login-box">
      <el-button class="login">登录</el-button>
      <el-button class="register">注册</el-button>
    </div>
    <hr />
    <div class="window-btn">
      <el-icon @click="ipcRenderer.send('min')"><Minus /></el-icon>
      <el-icon @click="ipcRenderer.send('max')"><FullScreen /></el-icon>
      <el-icon @click="ipcRenderer.send('close')"><Close /></el-icon>
    </div>
  </div>
</div>
</template>

<style lang="scss" scoped>
.top-column {
  overflow: hidden;
  display: flex;
  display: -webkit-flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  .top-left, .top-right {
    flex-shrink: 0;
    height: 100%;
    display: flex;
    display: -webkit-flex;
    align-items: center;
  }
  .top-left {
    margin-left: 5px;
    .logo {
      display: flex;
      display: -webkit-flex;
      align-items: center;
      font-size: 14px;
      margin-right: 30px;
      img {
        width: 24px;
        height: 24px;
        object-fit: contain;
        padding-right: 5px;
      }
    }
    .hostiry {
      display: flex;
      display: -webkit-flex;
      align-items: center;
      .el-icon {
        color: #666;
        cursor: pointer;
        &+.el-icon {
          margin-left: 10px;
        }
      }
    }
  }
  .seach {
    display: flex;
    display: -webkit-flex;
    align-items: center;
    :deep(.el-input) {
      border: none;
      border-radius: 40px;
      overflow: hidden;
      .el-input__wrapper {
        box-shadow: none;
        background-color: #f4f6fa;
      }
    }
  }
  .top-right {
    color: #222;
    .login-box {
      display: flex;
      display: -webkit-flex;
      margin-right: 10px;
      align-items: center;
      .el-button {
        border: none;
        background: #fff;
        color: #222;
        height: 1.6em;
        line-height: 1.6em;
        &:hover {
          color: #222;
          background: #f4f4f4;
        }
        &+.el-button {
          margin-left: 8px;
          background-color: #1b9367;
          color: white;
        }
      }
    }
    hr {
      width: 2px;
      background-color: #e9e9e9;
      border: none;
      height: 0.8em;
    }
    .window-btn {
      padding: 0 5px;
      height: 100%;
      .el-icon {
        cursor: pointer;
        height: 100%;
        padding: 0 5px;
        &:hover {
          background-color: #e9e9e9;
        }
      }
    }
  }
}
</style>
